﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace _4._3Counter
{
    class Program
    {
        static void Main(string[] args)
        {
            Count counter = new Count();
            List<Product> products = new List<Product>
            {
                new Product{ Id=1,Name="aa"},
                new Product{ Id=2,Name="bb"},
                new Product{ Id=3,Name="cc"},
                new Product{ Id=4,Name="dd"},

            };
            products.ForEach(p => Console.WriteLine(p.ToString()));//输出product所有元素的字符串
            Console.WriteLine("请输入Id");
            while (true)
            {
                int result;
                if (int.TryParse(Console.ReadLine(), out result))//输入数字
                {
                    var a = products.Where(p => p.Id == result).FirstOrDefault();
                    if (a != null) //如果有这个id
                        counter.AllCounter(a);

                    else
                        Console.WriteLine("没有这个id");
                }
                else
                    Console.WriteLine("请输入数字");
            }
        }
        public static void OK(Product product) => Console.WriteLine($"购买了：{product.Name}");
        public static void All(Product product) => Console.WriteLine($"用户{product.Name} ,购买次数剩余：{product.Num}");
        public static void No(Product product) => Console.WriteLine($"{product.Name}次数为null");
    }
}
